<?php
	namespace Common\Logic;
	use Common\Model\UserCourseLeaveModel;
	class UserCourseLeaveLogic extends UserCourseLeaveModel{
		/*
		* Function:		getUserCourseList
		* Description:	用户课程列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getUserCourseLeaveList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getUserCourseLeaveFilter($filter);
			return $this->alias('a')->join('left join course b on a.course_id=b.id')->field('a.*,b.title,b.cate_id,b.nums as all_nums,b.t_nums,b.begin_time,b.end_time,b.course_date,b.coach_id,b.classroom_id,b.level')->where($conditon)->order('a.id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getUserCourseFilter
		* Description:	用户课程列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getUserCourseLeaveFilter($filter = ''){
			$conditon = array();
			$conditon['a.is_deleted'] = 0;
            if(!empty($filter['status'])){
                $conditon['a.status'] = $filter['status'];
            }
			if(!empty($filter['user_id'])){
				$conditon['a.user_id'] = $filter['user_id'];
			}
			if(!empty($filter['store_id'])){
				$conditon['a.store_id'] = $filter['store_id'];
			}
			if(!empty($filter['cate_id'])){
				$conditon['b.cate_id'] = $filter['cate_id'];
			}
            if(!empty($filter['title'])){
                $conditon['b.title'] = array('like','%'.$filter['title'].'%');
            }
			return $conditon;
		}
		
		/*
		* Function:get:	getUserCourseCount
		* Description:	用户课程列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getUserCourseLeaveCount($filter = ''){
			$conditon = $this->getUserCourseLeaveFilter($filter);
			return $this->alias('a')->join('left join course b on a.course_id=b.id')->field('a.*,b.title,b.cate_id,b.nums,b.t_nums,b.begin_time,b.end_time')->where($conditon)->count();
		}
		
		/*
		* Function:		addUserCourse
		* Description:	增加用户课程
		* @param:		$data array 增加的数组
		*/
		public function addUserCourseLeave($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getUserCourseInfo
		* Description:	获取用户课程信息 by row
		* @param:		$id int ID
		*/
		public function getUserCourseLeaveInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateUserCourse
		* Description:	更新用户课程
		* @param:		$data array 更新的数组
		*/
		public function updateUserCourseLeave($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteUserCourse
		* Description:	删除用户课程
		* @param:		$id int ID
		*/
		public function deleteUserCourseLeave($id){
			return $this->where(array('id'=>$id))->delete();
		}
	}
?>